package com.sesame.consumer;

import kim.sesame.framework.rocketmq.msg.MsgConsumerService;
import kim.sesame.framework.utils.StringUtil;
import lombok.extern.apachecommons.CommonsLog;
import org.rocketmq.starter.annotation.RocketMQListener;
import org.rocketmq.starter.annotation.RocketMQMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.sesame.consumer.ConsumerService.topic1;

@CommonsLog
@Service
@RocketMQListener(topic = topic1)
public class ConsumerService {

    static final String topic1 = "test-topic-1";

    @RocketMQMessage(messageClass = String.class, tag = "tag1")
    public void tag1(String message) {
        log.info("-------ConsumerService tag1  --------");
        log.info(message);
        // 抛异常会让mq重新发送消息
//        if(message.length()>2){
//            throw new BusinessException("模拟一次");
//        }
    }

    @Autowired
    private MsgConsumerService msgConsumerService;

    @RocketMQMessage(messageClass = String.class, tag = "tag2")
    public void tag2(String message) {

        System.out.println(message);
        message = StringUtil.removeQuotes(message);
//        message = StringUtil.removeQuotes(message);
//        message = StringUtil.removeQuotes(message);
        System.out.println(message);

        try {
            msgConsumerService.msgConsole(message,(msg)->{
                log.info("-------ConsumerService tag2  --------");
                log.info(msg);
            });
        } catch (Exception e) {
            e.printStackTrace();
        }


    }


}
